package com.jeespring.account.service.impl;

import com.jeespring.account.dao.AccountDao;
import com.jeespring.dto.ResponseDTO;
import com.jeespring.entity.Account;
import com.jeespring.service.AccountService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Title: AccountService
 * @Description:
 * @Author 张朝阳
 * @Date 2020/11/29 13:34
 */
@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Override
    public List<Account> query(Account account) {
        return accountDao.select(account);
    }

    @Override
    public ResponseDTO decreaseAccount(Account account) {
        ResponseDTO<Object> response = new ResponseDTO<>();

        int count = accountDao.decrAccount(account.getUserId(), account.getAmount().doubleValue());
        if (count > 0){
            response.setSuccess(true);
            response.setMessage("扣减账号金额成功！");
            return response;
        }

        response.setSuccess(false);
        response.setMessage("扣减账号金额失败！");
        return response;
    }
}
